#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int dir[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
    string table = "frlb";
    while (k--)
    {
        int x, y;
        string s;
        cin >> x >> y >> s;
        for (auto c : s)
        {
            for (int i = 0; i < 4; ++i)
            {
                if (c == table[i])
                {
                    x = min(n, max(1, x + dir[i][0]));
                    y = min(n, max(1, y + dir[i][1]));
                }
            }
        }
        cout << x << " " << y << endl;
    }
}